package com.csu.controller;/*
 *
 * Author: Tianyu
 * Date: 2022/9/29 11:03:05
 */


import com.csu.system.domain.FaultInfo;
import com.csu.system.service.FaultInfoService;
import com.csu.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/system")
@Api(tags = "电解槽槽况信息")
public class FaultInfoController {

    private static final String prefix = "system";

    @Autowired
    private FaultInfoService faultInfoService;


    /**
     * 查询当前所有槽的最新故障
     * @param slotCnt 电解槽数量
     * @return
     */
    @GetMapping("/allFault/{slotCnt}")
    @ApiOperation(value = "获取全部槽的故障数据")
    @ResponseBody
    public JsonResult<List> getAllFaultInfo(@PathVariable("slotCnt") int slotCnt) {
        List<FaultInfo> list = faultInfoService.selectAllFaultInfo(slotCnt);
        return new JsonResult<>(list);
    }

    /**
     * 查询单槽最新故障
     * @param slotId 电解槽编号
     * @return
     */
    @GetMapping("/singleFault/{slotId}")
    @ApiOperation(value = "获取指定槽的故障数据")
    @ResponseBody
    public JsonResult<FaultInfo> getOneFaultInfo(@PathVariable("slotId") int slotId) {
        FaultInfo faultInfo = faultInfoService.selectOneFaultInfo(slotId);
        return new JsonResult<>(faultInfo);
    }

    /**
     * 查询当前所有槽的全部信息（故障、槽温、电压）
     * @param slotCnt
     * @return
     */
    @GetMapping("/allInfo/{slotCnt}")
    @ApiOperation(value = "获取全部槽的槽况信息")
    @ResponseBody
    public JsonResult<List> getAllSoltInfo(@PathVariable("slotCnt") int slotCnt) {
        List<FaultInfo> list = faultInfoService.selectAllSlotInfo(slotCnt);
        return new JsonResult<>(list);
    }

    /**
     * 查询指定槽的全部信息（故障、槽温、电压）
     * 注意：查询最近一次的全部槽信息，然后再筛选出目标槽，而不是直接查询全库
     * 上饶：24槽
     * @param slotId
     * @return
     */
    @GetMapping("/singleInfo/{slotId}")
    @ApiOperation(value = "获取指定槽的槽况信息")
    @ResponseBody
    public JsonResult<FaultInfo> getSingleSoltInfo(@PathVariable("slotId") int slotId) {
        FaultInfo faultInfo = faultInfoService.selectOneSlotInfo(slotId);
        return new JsonResult<>(faultInfo);
    }


    /**
     * 根据槽ID查询最近200条电压数据
     * @param slotId
     * @return
     */
    @GetMapping("/volList/{slotId}")
    @ApiOperation(value = "获取近期槽电压数据")
    @ResponseBody
    public JsonResult<List> getVolListbyId(@PathVariable("slotId") int slotId) {
        List<String> list = faultInfoService.selectVolList(slotId);
        List<Integer> res = list.stream().map(Integer::valueOf).collect(Collectors.toList());
        return new JsonResult<>(res);
    }


    @GetMapping("/")
    public String check() {
        return "/page/checking.html";
    }


    @GetMapping("/checking.html")
    public String check2() {
        return "/page/checking.html";
    }
    @GetMapping("/setting.html")
    public String setting() {
//        return "/page/setting.html";
        return "/page/noauth.html";
    }

    @GetMapping("/daily.html")
    public String daily() {
//        return "/page/daily.html";
        return "/page/noauth.html";
    }

    @GetMapping("/header.html")
    public String header() {
        return "/page/header.html";
    }

    @GetMapping("/about.html")
    public String about(){
        return "/page/about.html";
    }

    @GetMapping("/a")
    public String a() {
        return "/a.html";
    }
}
